﻿using Client.Components.Icons;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;

namespace Client.Components
{
    /// <summary>
    /// Icon 工具类
    /// </summary>
    public static class IconEnumUtils
    {
        /// <summary>
        /// 资源文件路径模板
        /// </summary>
        public const string Template = "pack://application:,,,/WPFControls;component/Resources/Icons";

        /// <summary>
        /// 获取资源文件路径
        /// </summary>
        /// <param name="icon"></param>
        /// <returns></returns>
        public static string GetIconResourcePath(this IconEnum icon)
        {
            string r = System.IO.Path.Combine(Template, $"{icon}.png");
            return r;
        }

        /// <summary>
        /// 获取默认值
        /// </summary>
        /// <param name="icon"></param>
        /// <returns></returns>
        public static string GetDefaultValue(this IconEnum icon)
        {
            //// 测试 : 切换为英文 
            //// 测试成功
            //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

            var currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            string uriStr = System.IO.Path.Combine(Template, $"Strings_{currentUICulture}.xaml");
            var dict = new ResourceDictionary { Source = new Uri(uriStr) };
            string key = $"IconEnum_{icon.ToString()}";
            
            if (dict.Contains(key) == false)
                return string.Empty;

            string r = dict[key].ToString();
            return r;
        }
    }
}
